package com.hsyt.pms.security.rsa.util;





import org.apache.commons.lang3.StringUtils;

import java.text.MessageFormat;

/**
 * @ClassName: OpenapiException
 * @Description: 开放平台顶级异常
 * @author 王勇琳
 * @date 2017年7月11日 下午5:25:02
 */
public class AmpSecurityException extends RuntimeException {
	private static final long serialVersionUID = 2965334374812355504L;
	
	private String errorCode;
	private String message;

	public String getErrorCode() {
		return errorCode;
	}

	public String getMessage() {
		return message;
	}

	public AmpSecurityException(String message, Throwable throwable){
		this(StringUtils.EMPTY, message, throwable);
	}
	
	public AmpSecurityException(String message){
		this(StringUtils.EMPTY, message, null);
	}
	
	public AmpSecurityException(String errorCode, String message, Throwable throwable) {
		super(MessageFormat.format("【errorCode：{0} message：{1}】", errorCode, message), throwable);
		this.errorCode = errorCode;
		this.message = message;
	}

	public AmpSecurityException(String errorCode, String message) {
		this(errorCode, message, null);
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((errorCode == null) ? 0 : errorCode.hashCode());
		result = prime * result + ((message == null) ? 0 : message.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}

		if (obj == null) {
			return false;
		}

		if (getClass() != obj.getClass()) {
			return false;
		}

		AmpSecurityException other = (AmpSecurityException) obj;
		if (errorCode == null) {
			if (other.errorCode != null) {
				return false;
			}
		} else if (!errorCode.equals(other.errorCode)) {
			return false;
		}
		if (message == null) {
			if (other.message != null) {
				return false;
			}

		} else if (!message.equals(other.message)) {
			return false;
		}

		return true;
	}

}
